x = input()
y = 0
if len(x) == 4:
    for i in range(0,4):
        for j in range(i + 1,5):
            s = 0
            for v in range(1,int(x[i:j])+1):
                if int(x[i:j])%v == 0:
                    s = s + 1
            if s == 2:
                c = int(x[i:j])
                y = max(y,c)
print(y)